package com.stylefeng.guns.rest.modular.film.service;

import com.stylefeng.guns.api.film.FilmAsyncServiceApi;
import com.stylefeng.guns.api.film.vo.ActorVO;
import com.stylefeng.guns.api.film.vo.FilmDescVO;
import com.stylefeng.guns.api.film.vo.ImgVO;
import com.stylefeng.guns.rest.common.persistence.dao.*;
import com.stylefeng.guns.rest.common.persistence.model.MoocActorT;
import com.stylefeng.guns.rest.common.persistence.model.MoocFilmInfoT;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class DefaultFilmAsyncServiceImpl implements FilmAsyncServiceApi {

    @Autowired
    private MoocFilmTMapper moocFilmTMapper;

    @Autowired
    private MoocBannerTMapper moocBannerTMapper;

    @Autowired
    private MoocCatDictTMapper moocCatDictTMapper;

    @Autowired
    private MoocYearDictTMapper moocYearDictTMapper;

    @Autowired
    private MoocSourceDictTMapper moocSourceDictTMapper;

    @Autowired
    private MoocActorTMapper moocActorTMapper;

    @Autowired
    private MoocFilmInfoTMapper moocFilmInfoTMapper;

    @Autowired
    private MoocFilmActorTMapper moocFilmActorTMapper;


    private MoocFilmInfoT getFilmInfo(String filmId){
        MoocFilmInfoT moocFilmInfo = new MoocFilmInfoT();
        moocFilmInfo.setFilmId(filmId);
        MoocFilmInfoT moocFilmInfoT = moocFilmInfoTMapper.selectOne(moocFilmInfo);

        return moocFilmInfoT;
    }

    @Override
    public FilmDescVO getFilmDesc(String filmId) {
        MoocFilmInfoT filmInfo = getFilmInfo(filmId);
        FilmDescVO filmDesc = new FilmDescVO();
        filmDesc.setBiography(filmInfo.getBiography());
        filmDesc.setFilmId(filmInfo.getFilmId());

        return filmDesc;
    }

    @Override
    public ImgVO getImgs(String filmId) {
        MoocFilmInfoT filmInfo = getFilmInfo(filmId);
        String imgStr = filmInfo.getFilmImgs();
        String[] imgs = imgStr.split(",");
        ImgVO img = new ImgVO();
        img.setMainImg(imgs[0]);
        img.setImg01(imgs[1]);
        img.setImg02(imgs[2]);
        img.setImg03(imgs[3]);
        img.setImg04(imgs[4]);

        return img;
    }

    @Override
    public ActorVO getDirector(String filmId) {
        MoocFilmInfoT filmInfo = getFilmInfo(filmId);
        ActorVO director = new ActorVO();
        Integer directorId = filmInfo.getDirectorId();
        MoocActorT moocActorT = moocActorTMapper.selectById(directorId);
        director.setDirectorName(moocActorT.getActorName());
        director.setImgAddress(moocActorT.getActorImg());


        return director;
    }

    @Override
    public List<ActorVO> getActors(String filmId) {

        List<ActorVO> actors = moocFilmActorTMapper.getActors(filmId);

        return actors;
    }
}
